﻿//Write a method that returns the index of the first element in array
//that is bigger than its neighbors, or -1, if there’s no such element.
//  Use the method from the previous exercise.


using System;
using System.Text;

public class BiggerThanItsNeighbors
{
    public static void Main()
    {
        Console.Write("Enter length of array L = ");
        int length = int.Parse(Console.ReadLine());
        double[] array = new double[length];
        PopulateArray(array);
        PrintArray(array);
        int index = 0;
        for (int i = 0; i < array.Length; i++)
        {
            if (i != index)
            {
                bool leftSide = false;
                bool rigthSide = false;
                if (index - 1 >= 0)
                {
                    leftSide = Check(array, index, index - 1, "");
                }
                if (index + 1 < array.Length)
                {
                    rigthSide = Check(array, index, index + 1, "");                    
                }
                if (leftSide && rigthSide)
                {
                    Console.WriteLine("Element at index {0} is bigger than left and right elements from it", index);
                    break;
                }
                if ( i == array.Length - 1)
                {
                    Console.WriteLine("No such element which is bigger from it neighbors");
                }
                index++;
            }
            
        }
    }

    private static bool Check(double[] array, int elementIndex, int currentIndex, string side)
    {
        if (array[elementIndex] > array[currentIndex])
        {
            return true;
        }
        else if (array[elementIndex] < array[currentIndex])
        {
            return false;
        }
        else
        {
            return false;
        }
    }

    private static void PopulateArray(double[] array)
    {
        Random rand = new Random();
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = rand.Next(-99, 100);
        }
    }

    private static void PrintArray(double[] array)
    {
        Console.Write("{");
        for (int i = 0; i < array.Length; i++)
        {
            if (i == array.Length - 1)
            {
                Console.Write("{0}}}", array[i]);
            }
            else
            {
                Console.Write("{0}, ", array[i]);
            }
        }

        Console.WriteLine();
    }
}